<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>SFMT: SFMT.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">SFMT
   &#160;<span id="projectnumber">1.4</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">SFMT.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_s_f_m_t_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#pragma once</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span>
<a name="l00035"></a>00035 <span class="preprocessor">#ifndef SFMTST_H</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#define SFMTST_H</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#if defined(__cplusplus)</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00039"></a>00039 <span class="preprocessor">#endif</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="preprocessor">#if defined(__STDC_VERSION__) &amp;&amp; (__STDC_VERSION__ &gt;= 199901L)</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span><span class="preprocessor">  #include &lt;inttypes.h&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#elif defined(_MSC_VER) || defined(__BORLANDC__)</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>  <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> uint32_t;
<a name="l00048"></a>00048   <span class="keyword">typedef</span> <span class="keywordtype">unsigned</span> __int64 uint64_t;
<a name="l00049"></a>00049 <span class="preprocessor">  #define inline __inline</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor">  #include &lt;inttypes.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">  #if defined(__GNUC__)</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">    #define inline __inline__</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">  #endif</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span>
<a name="l00057"></a>00057 <span class="preprocessor">#ifndef PRIu64</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">  #if defined(_MSC_VER) || defined(__BORLANDC__)</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">    #define PRIu64 &quot;I64u&quot;</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span><span class="preprocessor">    #define PRIx64 &quot;I64x&quot;</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span><span class="preprocessor">  #else</span>
<a name="l00062"></a><a class="code" href="_s_f_m_t_8h.html#ac582131d7a7c8ee57e73180d1714f9d5">00062</a> <span class="preprocessor"></span><span class="preprocessor">    #define PRIu64 &quot;llu&quot;</span>
<a name="l00063"></a><a class="code" href="_s_f_m_t_8h.html#aba38357387a474f439428dee1984fc5a">00063</a> <span class="preprocessor"></span><span class="preprocessor">    #define PRIx64 &quot;llx&quot;</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">  #endif</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span>
<a name="l00067"></a>00067 <span class="preprocessor">#include &quot;SFMT-params.h&quot;</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="comment">/*------------------------------------------</span>
<a name="l00070"></a>00070 <span class="comment">  128-bit SIMD like data type for standard C</span>
<a name="l00071"></a>00071 <span class="comment">  ------------------------------------------*/</span>
<a name="l00072"></a>00072 <span class="preprocessor">#if defined(HAVE_ALTIVEC)</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">  #if !defined(__APPLE__)</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">    #include &lt;altivec.h&gt;</span>
<a name="l00075"></a>00075 <span class="preprocessor">  #endif</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span>
<a name="l00077"></a>00077 <span class="keyword">union </span><a class="code" href="union_w128___t.html" title="128-bit data structure">W128_T</a> {
<a name="l00078"></a>00078     vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> s;
<a name="l00079"></a>00079     uint32_t <a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">u</a>[4];
<a name="l00080"></a>00080     uint64_t <a class="code" href="union_w128___t.html#ae222444071b31f65e53d6bbc3c3dd39e">u64</a>[2];
<a name="l00081"></a>00081 };
<a name="l00082"></a>00082 <span class="preprocessor">#elif defined(HAVE_SSE2)</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">  #include &lt;emmintrin.h&gt;</span>
<a name="l00084"></a>00084 
<a name="l00086"></a>00086 <span class="keyword">union </span><a class="code" href="union_w128___t.html" title="128-bit data structure">W128_T</a> {
<a name="l00087"></a>00087     uint32_t <a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">u</a>[4];
<a name="l00088"></a>00088     uint64_t <a class="code" href="union_w128___t.html#ae222444071b31f65e53d6bbc3c3dd39e">u64</a>[2];
<a name="l00089"></a>00089     __m128i si;
<a name="l00090"></a>00090 };
<a name="l00091"></a>00091 <span class="preprocessor">#else</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span>
<a name="l00093"></a><a class="code" href="union_w128___t.html">00093</a> <span class="keyword">union </span><a class="code" href="union_w128___t.html" title="128-bit data structure">W128_T</a> {
<a name="l00094"></a><a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">00094</a>     uint32_t <a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">u</a>[4];
<a name="l00095"></a><a class="code" href="union_w128___t.html#ae222444071b31f65e53d6bbc3c3dd39e">00095</a>     uint64_t <a class="code" href="union_w128___t.html#ae222444071b31f65e53d6bbc3c3dd39e">u64</a>[2];
<a name="l00096"></a>00096 };
<a name="l00097"></a>00097 <span class="preprocessor">#endif</span>
<a name="l00098"></a>00098 <span class="preprocessor"></span>
<a name="l00100"></a><a class="code" href="_s_f_m_t_8h.html#ab1ee414cba9ca0f33a3716e7a92c2b79">00100</a> <span class="keyword">typedef</span> <span class="keyword">union </span><a class="code" href="union_w128___t.html" title="128-bit data structure">W128_T</a> <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a>;
<a name="l00101"></a>00101 
<a name="l00105"></a><a class="code" href="struct_s_f_m_t___t.html">00105</a> <span class="keyword">struct </span><a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">SFMT_T</a> {
<a name="l00107"></a><a class="code" href="struct_s_f_m_t___t.html#a7bf9ad40f20e770d1e703b70248a5386">00107</a>     <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> <a class="code" href="struct_s_f_m_t___t.html#a7bf9ad40f20e770d1e703b70248a5386" title="the 128-bit internal state array">state</a>[SFMT_N];
<a name="l00109"></a><a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24">00109</a>     <span class="keywordtype">int</span> <a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a>;
<a name="l00110"></a>00110 };
<a name="l00111"></a>00111 
<a name="l00112"></a><a class="code" href="_s_f_m_t_8h.html#a786e4a6ba82d3cb2f62241d6351d973f">00112</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">SFMT_T</a> <a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a>;
<a name="l00113"></a>00113 
<a name="l00114"></a>00114 <span class="keywordtype">void</span> <a class="code" href="_s_f_m_t_8h.html#a04f57c1e9a6b5c0c52ac774a50da6c7e" title="This function generates pseudorandom 32-bit integers in the specified array[] by one call...">sfmt_fill_array32</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt, uint32_t * array, <span class="keywordtype">int</span> size);
<a name="l00115"></a>00115 <span class="keywordtype">void</span> <a class="code" href="_s_f_m_t_8h.html#ab9d6542bb167426bd35591afd32136af" title="This function generates pseudorandom 64-bit integers in the specified array[] by one call...">sfmt_fill_array64</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt, uint64_t * array, <span class="keywordtype">int</span> size);
<a name="l00116"></a>00116 <span class="keywordtype">void</span> <a class="code" href="_s_f_m_t_8h.html#a674d820db863265836ef9cb203aa4130" title="This function initializes the internal state array with a 32-bit integer seed.">sfmt_init_gen_rand</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt, uint32_t seed);
<a name="l00117"></a>00117 <span class="keywordtype">void</span> <a class="code" href="_s_f_m_t_8h.html#a28f357a6d2a9cd74cec3c9d458e58475" title="This function initializes the internal state array, with an array of 32-bit integers used as the seed...">sfmt_init_by_array</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt, uint32_t * init_key, <span class="keywordtype">int</span> key_length);
<a name="l00118"></a>00118 <span class="keyword">const</span> <span class="keywordtype">char</span> * <a class="code" href="_s_f_m_t_8h.html#a6454ae6ac89dbaa2fd5db79be99dd408" title="This function returns the identification string.">sfmt_get_idstring</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt);
<a name="l00119"></a>00119 <span class="keywordtype">int</span> <a class="code" href="_s_f_m_t_8h.html#a4a0698581c5ce4fdb269f814fd438a5f" title="This function returns the minimum size of array used for fill_array32() function.">sfmt_get_min_array_size32</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt);
<a name="l00120"></a>00120 <span class="keywordtype">int</span> <a class="code" href="_s_f_m_t_8h.html#a22ebb5ab2cf7e28d2bcf21ffffcc7e39" title="This function returns the minimum size of array used for fill_array64() function.">sfmt_get_min_array_size64</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt);
<a name="l00121"></a>00121 <span class="keywordtype">void</span> <a class="code" href="_s_f_m_t_8h.html#a2224d63688cbf9b1f50c01d5d9bb7f29" title="This function fills the internal state array with pseudorandom integers.">sfmt_gen_rand_all</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt);
<a name="l00122"></a>00122 
<a name="l00123"></a>00123 <span class="preprocessor">#ifndef ONLY64</span>
<a name="l00124"></a>00124 <span class="preprocessor"></span>
<a name="l00130"></a><a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110">00130</a> <span class="keyword">inline</span> <span class="keyword">static</span> uint32_t <a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt) {
<a name="l00131"></a>00131     uint32_t r;
<a name="l00132"></a>00132     uint32_t * psfmt32 = &amp;sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#a7bf9ad40f20e770d1e703b70248a5386" title="the 128-bit internal state array">state</a>[0].<a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">u</a>[0];
<a name="l00133"></a>00133 
<a name="l00134"></a>00134     <span class="keywordflow">if</span> (sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> &gt;= SFMT_N32) {
<a name="l00135"></a>00135         <a class="code" href="_s_f_m_t_8h.html#a2224d63688cbf9b1f50c01d5d9bb7f29" title="This function fills the internal state array with pseudorandom integers.">sfmt_gen_rand_all</a>(sfmt);
<a name="l00136"></a>00136         sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> = 0;
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138     r = psfmt32[sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a>++];
<a name="l00139"></a>00139     <span class="keywordflow">return</span> r;
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 <span class="preprocessor">#endif</span>
<a name="l00142"></a>00142 <span class="preprocessor"></span>
<a name="l00150"></a><a class="code" href="_s_f_m_t_8h.html#ae99df9ac1b48be1370492d448504b717">00150</a> <span class="keyword">inline</span> <span class="keyword">static</span> uint64_t <a class="code" href="_s_f_m_t_8h.html#ae99df9ac1b48be1370492d448504b717" title="This function generates and returns 64-bit pseudorandom number.">sfmt_genrand_uint64</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt) {
<a name="l00151"></a>00151 <span class="preprocessor">#if defined(BIG_ENDIAN64) &amp;&amp; !defined(ONLY64)</span>
<a name="l00152"></a>00152 <span class="preprocessor"></span>    uint32_t * psfmt32 = &amp;sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#a7bf9ad40f20e770d1e703b70248a5386" title="the 128-bit internal state array">state</a>[0].<a class="code" href="union_w128___t.html#a09193c7aed9f152649d36a78792ffd11">u</a>[0];
<a name="l00153"></a>00153     uint32_t r1, r2;
<a name="l00154"></a>00154 <span class="preprocessor">#else</span>
<a name="l00155"></a>00155 <span class="preprocessor"></span>    uint64_t r;
<a name="l00156"></a>00156 <span class="preprocessor">#endif</span>
<a name="l00157"></a>00157 <span class="preprocessor"></span>    uint64_t * psfmt64 = &amp;sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#a7bf9ad40f20e770d1e703b70248a5386" title="the 128-bit internal state array">state</a>[0].<a class="code" href="union_w128___t.html#ae222444071b31f65e53d6bbc3c3dd39e">u64</a>[0];
<a name="l00158"></a>00158     assert(sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> % 2 == 0);
<a name="l00159"></a>00159 
<a name="l00160"></a>00160     <span class="keywordflow">if</span> (sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> &gt;= SFMT_N32) {
<a name="l00161"></a>00161         <a class="code" href="_s_f_m_t_8h.html#a2224d63688cbf9b1f50c01d5d9bb7f29" title="This function fills the internal state array with pseudorandom integers.">sfmt_gen_rand_all</a>(sfmt);
<a name="l00162"></a>00162         sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> = 0;
<a name="l00163"></a>00163     }
<a name="l00164"></a>00164 <span class="preprocessor">#if defined(BIG_ENDIAN64) &amp;&amp; !defined(ONLY64)</span>
<a name="l00165"></a>00165 <span class="preprocessor"></span>    r1 = psfmt32[sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a>];
<a name="l00166"></a>00166     r2 = psfmt32[sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> + 1];
<a name="l00167"></a>00167     sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> += 2;
<a name="l00168"></a>00168     <span class="keywordflow">return</span> ((uint64_t)r2 &lt;&lt; 32) | r1;
<a name="l00169"></a>00169 <span class="preprocessor">#else</span>
<a name="l00170"></a>00170 <span class="preprocessor"></span>    r = psfmt64[sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> / 2];
<a name="l00171"></a>00171     sfmt-&gt;<a class="code" href="struct_s_f_m_t___t.html#adff6ae93dbd68c2f74a96b99367aba24" title="index counter to the 32-bit internal state array">idx</a> += 2;
<a name="l00172"></a>00172     <span class="keywordflow">return</span> r;
<a name="l00173"></a>00173 <span class="preprocessor">#endif</span>
<a name="l00174"></a>00174 <span class="preprocessor"></span>}
<a name="l00175"></a>00175 
<a name="l00176"></a>00176 <span class="comment">/* =================================================</span>
<a name="l00177"></a>00177 <span class="comment">   The following real versions are due to Isaku Wada</span>
<a name="l00178"></a>00178 <span class="comment">   ================================================= */</span>
<a name="l00184"></a><a class="code" href="_s_f_m_t_8h.html#a29ed9f4537b9e617737dc32585636000">00184</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a29ed9f4537b9e617737dc32585636000" title="converts an unsigned 32-bit number to a double on [0,1]-real-interval.">sfmt_to_real1</a>(uint32_t v)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186     <span class="keywordflow">return</span> v * (1.0/4294967295.0);
<a name="l00187"></a>00187     <span class="comment">/* divided by 2^32-1 */</span>
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00195"></a><a class="code" href="_s_f_m_t_8h.html#ac8f1ec46b29372bbd2dd311ce2887ebf">00195</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#ac8f1ec46b29372bbd2dd311ce2887ebf" title="generates a random number on [0,1]-real-interval">sfmt_genrand_real1</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt)
<a name="l00196"></a>00196 {
<a name="l00197"></a>00197     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#a29ed9f4537b9e617737dc32585636000" title="converts an unsigned 32-bit number to a double on [0,1]-real-interval.">sfmt_to_real1</a>(<a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(sfmt));
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 
<a name="l00205"></a><a class="code" href="_s_f_m_t_8h.html#a4caa47d7e18ec69f30a56f9390fda3e7">00205</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a4caa47d7e18ec69f30a56f9390fda3e7" title="converts an unsigned 32-bit integer to a double on [0,1)-real-interval.">sfmt_to_real2</a>(uint32_t v)
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207     <span class="keywordflow">return</span> v * (1.0/4294967296.0);
<a name="l00208"></a>00208     <span class="comment">/* divided by 2^32 */</span>
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00216"></a><a class="code" href="_s_f_m_t_8h.html#a3e68d5e08ce1841614dbd93cc4cfa251">00216</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a3e68d5e08ce1841614dbd93cc4cfa251" title="generates a random number on [0,1)-real-interval">sfmt_genrand_real2</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt)
<a name="l00217"></a>00217 {
<a name="l00218"></a>00218     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#a4caa47d7e18ec69f30a56f9390fda3e7" title="converts an unsigned 32-bit integer to a double on [0,1)-real-interval.">sfmt_to_real2</a>(<a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(sfmt));
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 
<a name="l00226"></a><a class="code" href="_s_f_m_t_8h.html#a48d93f237f52b2a149ab0d683527aa9c">00226</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a48d93f237f52b2a149ab0d683527aa9c" title="converts an unsigned 32-bit integer to a double on (0,1)-real-interval.">sfmt_to_real3</a>(uint32_t v)
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228     <span class="keywordflow">return</span> (((<span class="keywordtype">double</span>)v) + 0.5)*(1.0/4294967296.0);
<a name="l00229"></a>00229     <span class="comment">/* divided by 2^32 */</span>
<a name="l00230"></a>00230 }
<a name="l00231"></a>00231 
<a name="l00237"></a><a class="code" href="_s_f_m_t_8h.html#a89e02c7333287e1ca650c38983ab6dae">00237</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a89e02c7333287e1ca650c38983ab6dae" title="generates a random number on (0,1)-real-interval">sfmt_genrand_real3</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt)
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#a48d93f237f52b2a149ab0d683527aa9c" title="converts an unsigned 32-bit integer to a double on (0,1)-real-interval.">sfmt_to_real3</a>(<a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(sfmt));
<a name="l00240"></a>00240 }
<a name="l00241"></a>00241 
<a name="l00248"></a><a class="code" href="_s_f_m_t_8h.html#abd5780d6ef5e9836a63e555e9f7da940">00248</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#abd5780d6ef5e9836a63e555e9f7da940" title="converts an unsigned 32-bit integer to double on [0,1) with 53-bit resolution.">sfmt_to_res53</a>(uint64_t v)
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250     <span class="keywordflow">return</span> v * (1.0/18446744073709551616.0L);
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 
<a name="l00258"></a><a class="code" href="_s_f_m_t_8h.html#aa5b6472af111363e237ae022f6a9ef48">00258</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#aa5b6472af111363e237ae022f6a9ef48" title="generates a random number on [0,1) with 53-bit resolution">sfmt_genrand_res53</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt)
<a name="l00259"></a>00259 {
<a name="l00260"></a>00260     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#abd5780d6ef5e9836a63e555e9f7da940" title="converts an unsigned 32-bit integer to double on [0,1) with 53-bit resolution.">sfmt_to_res53</a>(<a class="code" href="_s_f_m_t_8h.html#ae99df9ac1b48be1370492d448504b717" title="This function generates and returns 64-bit pseudorandom number.">sfmt_genrand_uint64</a>(sfmt));
<a name="l00261"></a>00261 }
<a name="l00262"></a>00262 
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 <span class="comment">/* =================================================</span>
<a name="l00265"></a>00265 <span class="comment">   The following function are added by Saito.</span>
<a name="l00266"></a>00266 <span class="comment">   ================================================= */</span>
<a name="l00271"></a><a class="code" href="_s_f_m_t_8h.html#a686d9c9d19ba29e0890abd2127f46339">00271</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a686d9c9d19ba29e0890abd2127f46339" title="generates a random number on [0,1) with 53-bit resolution from two 32 bit integers">sfmt_to_res53_mix</a>(uint32_t x, uint32_t y)
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#abd5780d6ef5e9836a63e555e9f7da940" title="converts an unsigned 32-bit integer to double on [0,1) with 53-bit resolution.">sfmt_to_res53</a>(x | ((uint64_t)y &lt;&lt; 32));
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 
<a name="l00282"></a><a class="code" href="_s_f_m_t_8h.html#a6b92b2435f0182f5fa19f94bb7986d74">00282</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="_s_f_m_t_8h.html#a6b92b2435f0182f5fa19f94bb7986d74" title="generates a random number on [0,1) with 53-bit resolution using two 32bit integers.">sfmt_genrand_res53_mix</a>(<a class="code" href="struct_s_f_m_t___t.html" title="SFMT internal state.">sfmt_t</a> * sfmt)
<a name="l00283"></a>00283 {
<a name="l00284"></a>00284     uint32_t x, y;
<a name="l00285"></a>00285 
<a name="l00286"></a>00286     x = <a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(sfmt);
<a name="l00287"></a>00287     y = <a class="code" href="_s_f_m_t_8h.html#a320ad3d4b201c8b5525871b5d4c9d110" title="This function generates and returns 32-bit pseudorandom number.">sfmt_genrand_uint32</a>(sfmt);
<a name="l00288"></a>00288     <span class="keywordflow">return</span> <a class="code" href="_s_f_m_t_8h.html#a686d9c9d19ba29e0890abd2127f46339" title="generates a random number on [0,1) with 53-bit resolution from two 32 bit integers">sfmt_to_res53_mix</a>(x, y);
<a name="l00289"></a>00289 }
<a name="l00290"></a>00290 
<a name="l00291"></a>00291 <span class="preprocessor">#if defined(__cplusplus)</span>
<a name="l00292"></a>00292 <span class="preprocessor"></span>}
<a name="l00293"></a>00293 <span class="preprocessor">#endif</span>
<a name="l00294"></a>00294 <span class="preprocessor"></span>
<a name="l00295"></a>00295 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Jun 28 2012 10:34:10 for SFMT by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
